 //获取焦点变色
 var regFoucs = function(ele){
	 //边框变色
	 $(ele).css({"border":"1px solid","border-color":"#ff9900"});
 }
// 失去焦点结果为ture时的变色
var regRight = function(ele){
	//输入框颜色变为绿色
	$(ele).css({"border":"1px solid","border-color":"#59A358"});
	//输入框字体变为黑色
	$(ele).css("color","#000000");
}
//失去焦点结果为false时变色
var regWorng = function(ele){
	//输入框颜色变为红色
	$(ele).css({"border":"1px solid","border-color":"#e60000"});
	//输入框字体变为红色
	$(ele).css("color","#e60000");
}
//当手机号码输入框获取焦点
$("#phone-ipt").eq(0).focus(function(){
// 	//正确图标消失
	$(".proper_icon").css("display","none");
	regFoucs($(this));
})
var phone = false;
//手机号码输入框失去焦点时;
$("#phone-ipt").blur(function(){
	//如果手机号不正确或输入框为空,返回false
	if(!(/^1[34578]\d{9}$/.test($("#phone-ipt").val())) || $("#phone-ipt").val() == null){ 
		//错误图标出现
        $("#Error-1").css("display","block");
		regWorng($(this));
		phone = false
	}else{
		//错误提示框隐藏
		$("#Error-1").css("display","none");
		//正确图标显示
		$(".proper_icon").css("display","block");
		regRight($(this));
		phone = true;
	}
 });
 
 
 
 var password = false;
 // 输入密码获取焦点
 $("#password-ipt").eq(0).focus(function(){
	 //正确图标消失
	 $(".proper_icon_pass").css("display","none");
	 regFoucs($(this));
 })
 
//声明变量regPassword的构造函数
var regPassword = function(passWord){
	//将正则的三个验证保存到regArr数组中
	var regArr = [
		{reg:/^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+){6,20}$/,text:'密码强度：弱'},
		{reg:/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/,text:'密码强度：中'},
		{reg:/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/,text:'密码强度：强'}
		];
	//假设passFalse为false
	var passFalse = false;
	//定义空字符串
	var text = '';
	// 循环遍历regArr数组中的元素 
	for(var i = 0 ; i < regArr.length;i++){
		//如果获取焦点的元素存在
		if(regArr[i].reg.test(passWord)){
			//让passFalse为true
			passFalse = true;
			//将text的innerHTML赋值给空的text
			text = regArr[i].text;
			//停止循环
			break;
		}
	}
	//如果passFalse为true 执行下面的代码
	if(passFalse){
		//报错提示框隐藏
		$("#Error-2").css("display","none");
		//正确图标显示
		$(".proper_icon_pass").css("display","block");
		//密码强度提示显示
		$(".pass_span").css("display","block");
		//修改提示框文字
		$(".pass_span").html(text);
		regRight($("#password-ipt"));
		password = true;
	}else{
		$("#Error-2").css("display","block");
		$(".proper_icon_pass").css("display","none");
		regWorng($("#password-ipt"));
		//密码强度显示隐藏
		$(".pass_span").css("display","none");
		password = false;
	}
}

 //输入密码失去焦点;
 $("#password-ipt").blur(function(){
	 //调用构造函数
	 regPassword($(this).val());
 })
 
 var passAgain = false;
 //确认密码获得焦点
 $("#passArgin-ipt").eq(0).focus(function(){
	 //正确图标消失
	 $(".proper_passArgin").css("display","none");
	 regFoucs($(this));

 })
 //确认密码失去焦点
 $("#passArgin-ipt").blur(function(){
	 if( $("#password-ipt").val() != $("#passArgin-ipt").val() || $("#passArgin-ipt").val().length == 0){
		 //错误提示框显示
		 $("#Error-3").css("display","block");
		 //正确提示框隐藏
		 $(".proper_passArgin").css("display","none");
		 regWorng($(this));
		 passAgain = false;
	 }else{
		 //报错提示框隐藏
		 $("#Error-3").css("display","none");
		 //正确图标显示
		 $(".proper_passArgin").css("display","block");
		regRight($(this));
		passAgain = true;
	 }
 })

 //提交按钮点击事件
 $("#ipt_button").on("click",function(){
	 console.log(phone,password,passAgain)
	 if(phone == false || password == false || passAgain == false){
		 $("#Error-1").css("display","block");
		 $("#Error-2").css("display","block");
		 $("#Error-3").css("display","block");
	 }else if($("#phone-ipt").val().length == 0 || $("#password-ipt").length == 0 || $("#passArgin-ipt").length == 0 ){
		 $("#Error-1").css("display","block");
		 $("#Error-2").css("display","block");
		 $("#Error-3").css("display","block");
	 }else{
		 var url = "http://jx.xuzhixiang.top/ap/api/reg.php";
		 $.ajax({
			 url:url,
			 type:"get",
			 data:{
					"username":$("#phone-ipt").val(),
					"password":$("#password-ipt").val()
				  },
			 success:function(res){
				 console.log(res);
				 var obj = JSON.parse(res);
				 if(obj.code){
					 alert("注册成功");
					 $(location).attr('href', 'Sign.html');
				 }else{
					alert("注册失败");
				 }
			 }
		 })
		 
		 
	 }
 })